﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using System.Xml.Serialization;
using System.IO;

using Shared;
using Shared.Database;
using Shared.NetWork;

namespace CharacterServer
{
    [ISerializableAttribute((long)Opcodes.LobbyCharacterDelete)]
    public class LobbyCharacterDelete : ISerializablePacket
    {
        [ArrayBit(0)]
        public string UnkText;

        [Raw8Bit(1)]
        public long GUID;

        public override void OnRead(RiftClient From)
        {
            Character[] Chars = CharacterMgr.Instance.GetCharacters(From.Acct.Id, From.Realm.RealmId);

            long pGUID = ByteOperations.ByteSwap.Swap(GUID);

            foreach (Character charac in Chars)
                if (charac.Id == pGUID)
                    CharacterMgr.Instance.RemoveObject(charac);

            ISerializablePacket DeleteResult = new ISerializablePacket();
            DeleteResult.Opcode = (long)Opcodes.LobbyCharacterDeleteOk;
            DeleteResult.AddField(0, EPacketFieldType.Unsigned7BitEncoded, (long)0); // Result, 15 Error must wait logout, 0 OK

            From.SendSerialized(DeleteResult);
        }
    }
}
